package com.industrial.operation.controller;

import com.industrial.common.core.utils.StringUtils;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationGdp;
import com.industrial.operation.service.IOperationGdpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

/**
 * 制造业增加值占GDP比重Controller
 *
 * @author Zhou_S
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/gdp")
public class OperationGdpController extends BaseController
{
    @Autowired
    private IOperationGdpService operationGdpService;

    /**
     * 查询制造业增加值占GDP比重列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OperationGdp operationGdp)
    {
        startPage();
      if(StringUtils.isNull(operationGdp.getYears())){
            LocalDate localDate = LocalDate.now();
            operationGdp.setYears(String.valueOf(localDate.getYear()));
        }
        List<OperationGdp> list = operationGdpService.selectOperationGdpList(operationGdp);
        return getDataTable(list);
    }

    /**
     * 导出制造业增加值占GDP比重列表
     */
    @RequiresPermissions("@ss.hasPermi('operation:gdp:export')")
    @Log(title = "制造业增加值占GDP比重", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationGdp operationGdp)
    {
        List<OperationGdp> list = operationGdpService.selectOperationGdpList(operationGdp);
        ExcelUtil<OperationGdp> util = new ExcelUtil<OperationGdp>(OperationGdp.class);
        util.exportExcel(response, list, "制造业增加值占GDP比重数据");
    }

    /**
     * 获取制造业增加值占GDP比重详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationGdpService.selectOperationGdpByBaseId(baseId));
    }

    /**
     * 新增制造业增加值占GDP比重
     */
    @Log(title = "制造业增加值占GDP比重", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationGdp operationGdp)
    {
        LocalDate localDate = LocalDate.now();
        operationGdp.setYears(String.valueOf(localDate.getYear()));
        return toAjax(operationGdpService.insertOperationGdp(operationGdp));
    }

    /**
     * 修改制造业增加值占GDP比重
     */
    @RequiresPermissions("@ss.hasPermi('operation:gdp:edit')")
    @Log(title = "制造业增加值占GDP比重", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationGdp operationGdp)
    {
        return toAjax(operationGdpService.updateOperationGdp(operationGdp));
    }

    /**
     * 删除制造业增加值占GDP比重
     */
    @Log(title = "制造业增加值占GDP比重", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationGdpService.deleteOperationGdpByBaseIds(baseIds));
    }

    @GetMapping(value = "sum")
    public AjaxResult sum(String years)
    {
      if(StringUtils.isNull(years)){
            LocalDate localDate = LocalDate.now();
            years=String.valueOf(localDate.getYear());
        }
        List<OperationGdp> list=  operationGdpService.sum(years);
        return success(list);
    }




}
